Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MkCritic

github Show source on GitHub

MkCritic block.

Examples

Example: Addition

Note

Jinja

{{ "Type `addition`" | MkCritic(typ="addition") }}

Note

Python

MkCritic(None, typ='addition')
Rendered

Type addition

Markdown
<ins>

Type `addition`

</ins>
Html
<ins>
<p>Type <code>addition</code></p>
</ins>

GitHub
<ins>

Type `addition`

</ins>
Repr tree
MkCritic
╰── MkText('Type `addition`')

Example: Deletion

Note

Jinja

{{ "Type `deletion`" | MkCritic(typ="deletion") }}

Note

Python

MkCritic(None, typ='deletion')
Rendered

Type deletion

Markdown
<del>

Type `deletion`

</del>
Html
<del>
<p>Type <code>deletion</code></p>
</del>

GitHub
<del>

Type `deletion`

</del>
Repr tree
MkCritic
╰── MkText('Type `deletion`')

Example: Highlight

Note

Jinja

{{ "Type `highlight`" | MkCritic(typ="highlight") }}

Note

Python

MkCritic(None)
Rendered

Type highlight

Markdown
<mark>

Type `highlight`

</mark>
Html
<mark>
<p>Type <code>highlight</code></p>
</mark>

GitHub
<mark>

Type `highlight`

</mark>
Repr tree
MkCritic
╰── MkText('Type `highlight`')

Example: Comment

Note

Jinja

{{ "Type `comment`" | MkCritic(typ="comment") }}

Note

Python

MkCritic(None, typ='comment')
Rendered
Markdown
<!-- Type `comment` -->
Html
<!-- Type `comment` -->

GitHub
<!-- Type `comment` -->
Repr tree
MkCritic
╰── MkText('Type `comment`')
DocStrings

class MkCritic(mkcontainer.MkContainer)
Base classes
NameChildrenInherits
MkContainer
mknodes.basenodes.mkcontainer
A node containing other MkNodes.
⋔ Inheritance diagram
graph TD
  832683224["mkcritic.MkCritic"]
  835538629["mkcontainer.MkContainer"]
  1956333208["mkcontainer.MkContainerBase"]
  1359323199["mknode.MkNode"]
  2751680898["builtins.object"]
  835538629 --> 832683224
  1956333208 --> 835538629
  1359323199 --> 1956333208
  2751680898 --> 1359323199
NodeFile

/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkcritic/metadata.toml

[metadata]
icon = "mdi:format-text"
name = "MkCritic"

[requirements.extension."pymdownx.critic"]

[examples.addition]
title = "Addition"
jinja = """
{{ "Type `addition`" | MkCritic(typ="addition") }}
"""

[examples.deletion]
title = "Deletion"
jinja = """
{{ "Type `deletion`" | MkCritic(typ="deletion") }}
"""

[examples.highlight]
title = "Highlight"
jinja = """
{{ "Type `highlight`" | MkCritic(typ="highlight") }}
"""

[examples.comment]
title = "Comment"
jinja = """
{{ "Type `comment`" | MkCritic(typ="comment") }}
"""

[output.markdown]
template = """
{% raw %}{{% endraw %}{{ node.marks[0] }}

{{ node.get_items() | join(node.block_separator) }}

{{ node.marks[1] }}{% raw %}}{% endraw %}
"""

Code

mknodes.basenodes.mkcritic.MkCritic

class MkCritic(mkcontainer.MkContainer):
    """MkCritic block."""

    ICON = "material/format-text"
    REQUIRED_EXTENSIONS = [resources.Extension("pymdownx.critic")]

    def __init__(
        self,
        content: str | mk.MkNode | list,
        *,
        typ: CriticMarkStr = "highlight",
        **kwargs: Any,
    ) -> None:
        """Constructor.

        Args:
            content: Content to mark
            typ: Mark type
            kwargs: Keyword arguments passed to parent
        """
        super().__init__(content=content, **kwargs)
        self.typ = typ

    @property
    def marks(self) -> tuple[str, str]:
        match self.typ:
            case "addition":
                return ("++", "++")
            case "deletion":
                return ("--", "--")
            case "highlight":
                return ("==", "==")
            case "comment":
                return (">>", "<<")
            case _:
                raise TypeError(self.typ)

    def get_content(self) -> resources.NodeContent:
        """Single-pass: get content with critic formatting and resources."""
        content = super().get_content()
        left, right = self.marks
        md = f"{{{left}\n\n{content.markdown}\n\n{right}}}"
        return resources.NodeContent(markdown=md, resources=content.resources)

    def to_md_unprocessed(self) -> str:
        content = self.get_content()
        return content.markdown

Page info
Code for this page

mknodes.manual.nodes_section.create_section_for_nodes

def create_section_for_nodes(
    nav: mk.MkNav,
    klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
    for kls in klasses:
        tpl = "classpage_custom.jinja"
        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
        nav += page
        if kls.STATUS:
            page.metadata.status = kls.STATUS
        elif kls.JS_FILES:
            page.metadata.status = "js"
        elif kls.CSS:
            page.metadata.status = "css"
        page.created_by = create_section_for_nodes
        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
        table.add_row((link, kls.__doc__, extensions))
    return table

Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                           'format': <function fence_code_format at 0x7d707a397060>,
                                                                           'name': 'mermaid'}]},
                               'pymdownx.tabbed': {},
                               'tables': {}},
          plugins=[Plugin('mkdocstrings')],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
  source_function: create_section_for_nodes
  source_line_no: 93
hide:
- toc
icon: material/format-text
title: MkCritic